package cn.edu.gdut.deepcode.config;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * <p>
 * 用于获取HttpSession对象
 * </p>
 *
 * @Author: myc
 * @Since: 2025-04-14  23:05
 * @Version: 1.0.0
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator{

    /*
    * 握手方法
    * */
    @Override
    public void modifyHandshake(ServerEndpointConfig sec,   //配置对象
                                  HandshakeRequest request,   //握手请求对象
                                  HandshakeResponse response){   //握手请求对象
        //获取HttpSession对象
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        //将HttpSession对象存储到配置对象中
        sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
    }

}
